#include "project.h"

/*获取网页数据缓冲区*/
char temp_up[4] = {0};
char temp_low[4] = {0};
char hum_up[4] = {0};
char hum_low[4] = {0};
char illu_up[4] = {0};
char illu_low[4] = {0};

int cgiMain(int argc, const char *argv[])
{
	cgiFormString("temp_up",temp_up,4);//获取网页form表单 温度值
	cgiFormString("temp_low",temp_low,4);
	
	cgiFormString("hum_up",hum_up,4);//获取网页form表单 湿度值
	cgiFormString("hum_low",hum_low,4);
	
	cgiFormString("illu_up",illu_up,4);//获取网页form表单 光强度值
	cgiFormString("illu_low",illu_low,4);
	
	/*创建消息队列*/
	key_t key = 0; 
	if((key = ftok("/home/linux",'a')) == -1) 
	{ 
		perror("ftok"); 
		return -1; 
	}

	msqid = msgget(key,IPC_CREAT|0666); 
	if(msqid == -1) { 
		perror("msgget"); 
		return -1; 
	}
	
	//写入公共空间
	memset(&msg,0,sizeof(msg_t));

	msg.env_set_msg.tmp_up = atoi(temp_up);
	msg.env_set_msg.tmp_dow = atoi(temp_low);
	msg.env_set_msg.hum_up = atoi(hum_up);
	msg.env_set_msg.hum_dow = atoi(hum_low);
	msg.env_set_msg.illu_up = atoi(illu_up);
	msg.env_set_msg.illu_dow = atoi(illu_low);

	msg.mtype = 3;
	msg.store_num = 1;
	msgsnd(msqid,&msg,sizeof(msg_t)-sizeof(long),0);	
		
	printf("Content-type: text/html;charset=\"UTF-8\"\n\n");

	printf("<html>");	
	printf("<body bgcolor=\"green\">\n");
	
	printf("<script>window.location.href = '../one_store.html';</script>\n");

	printf("</body>\n");
	printf("</html>\n");
	
	return 0;
}
